import wepy from 'wepy'
import * as tip from './tip'
async function uploadFile(param) {
  let params = {
    header: {
      authentication: `USERID ${wx.getStorageSync('authentication')}`
    },
    name: 'files'
  }
  Object.assign(params, param)
  try {
    let data = await wepy.uploadFile(params)
    data = JSON.parse(data.data)
    console.log(data)
    return new Promise((resolve) => {
      if (data.code === 200) {
        resolve(data)
      } else {
        resolve(data)
      }
    })
  } catch (err) {
    tip.showToast('上传失败,请重试', 'none')
    console.log(err)
  }
}

module.exports = {
  uploadFile
}
